﻿namespace Sharp.Platform.Mvc.Bootstrap
{
    /// <summary>
    /// 按钮扩展方法。
    /// </summary>
    public static class LinkButtonExtensions
    {
        public static LinkButtonBuilder LinkButton(this BootstrapFactory factory)
        {
            return new LinkButtonBuilder();
        }

        public static LinkButtonBuilder LinkButton(this BootstrapFactory factory, string title, ToolBarIco ico)
        {
            var bb = factory.LinkButton().Title(title);
            bb.TagBuilder.InnerHtml = "<span>" + bb.TagBuilder.InnerHtml + "</span>";
            switch (ico)
            {
                case ToolBarIco.Details:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-files-o\"></i> " + bb.TagBuilder.InnerHtml;
                    break;
                case ToolBarIco.Create:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-plus\"></i> " + bb.TagBuilder.InnerHtml;
                    break;
                case ToolBarIco.Edit:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-pencil\"></i> " + bb.TagBuilder.InnerHtml;
                    break;
                case ToolBarIco.Delete:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-trash\"></i> " + bb.TagBuilder.InnerHtml;
                    bb.Style().Danger();
                    break;
                case ToolBarIco.Import:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-file-excel-o\"></i> " + bb.TagBuilder.InnerHtml;
                    break;
                case ToolBarIco.Export:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-file-text-o\"></i> " + bb.TagBuilder.InnerHtml;
                    break;
                case ToolBarIco.Permission:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-paragraph\"></i> " + bb.TagBuilder.InnerHtml;
                    break;
                case ToolBarIco.Refresh:
                    bb.TagBuilder.InnerHtml = "<i class=\"fa fa-refresh\"></i> " + bb.TagBuilder.InnerHtml;
                    break;
            }

            return bb;
        }


        public static LinkButtonBuilder LoadingText(this LinkButtonBuilder factory, string text)
        {
            return factory.Attribute("data-loading-text", text, true);
        }
        /// <summary>
        /// 访问路径，用来作权限判断的
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="route">路由</param>
        /// <returns></returns>
        public static LinkButtonBuilder Route(this LinkButtonBuilder factory, string route)
        {
            return factory.Attribute("data-route", route, true);
        }
        /// <summary>
        /// 权限代码用来作权限判断
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="code">权限代码</param>
        /// <returns></returns>
        public static LinkButtonBuilder Permission(this LinkButtonBuilder factory, string code)
        {
            return factory.Attribute("data-permission", code, true);
        }
    }
    /// <summary>
    /// 工具栏按钮图标
    /// </summary>
    public enum ToolBarIco
    {
        /// <summary>
        /// 不设置图标
        /// </summary>
        None,
        /// <summary>
        /// 新增
        /// </summary>
        Create,
        /// <summary>
        /// 修改
        /// </summary>
        Edit,
        /// <summary>
        /// 删除
        /// </summary>
        Delete,
        /// <summary>
        /// 导入
        /// </summary>
        Import,
        /// <summary>
        /// 导出
        /// </summary>
        Export,
        /// <summary>
        /// 权限
        /// </summary>
        Permission,
        /// <summary>
        /// 刷新
        /// </summary>
        Refresh,
        /// <summary>
        /// 审核
        /// </summary>
        Checkin,
        Details
    }

}